<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="专家类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['professorType']" placeholder="请输入专家类型"></a-input>
        </a-form-item>
        <a-form-item label="专家姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['professorName']" placeholder="请输入专家姓名"></a-input>
        </a-form-item>
        <a-form-item label="专家性别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['professorSex']" :trigger-change="true" dictCode="sex" placeholder="请选择专家性别"/>
        </a-form-item>
        <a-form-item label="出生年月" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择出生年月" v-decorator="['professorBirthday']" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="毕业院校" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['professorSchool']" :trigger-change="true" dictCode="" placeholder="请选择毕业院校"/>
        </a-form-item>
        <a-form-item label="所学专业" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['professorMajor']" :trigger-change="true" dictCode="" placeholder="请选择所学专业"/>
        </a-form-item>
        <a-form-item label="毕业时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择毕业时间" v-decorator="['professorGraduateDate']" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="学历" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['professorEducationBackground']" placeholder="请输入学历"></a-input>
        </a-form-item>
        <a-form-item label="学位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['professorDegree']" placeholder="请输入学位"></a-input>
        </a-form-item>
        <a-form-item label="工作单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['professorWorkUnit']" placeholder="请输入工作单位"></a-input>
        </a-form-item>
        <a-form-item label="通讯地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['professorAddress']" placeholder="请输入通讯地址"></a-input>
        </a-form-item>
        <a-form-item label="申报类别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['professorDeclareCategory']" :trigger-change="true" dictCode="" placeholder="请选择申报类别"/>
        </a-form-item>
        <a-form-item label="职务" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['professorPosition']" :trigger-change="true" dictCode="" placeholder="请选择职务"/>
        </a-form-item>
        <a-form-item label="参加工作时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择参加工作时间" v-decorator="['professorBeginWork']" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="技术职称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['professorTitle']" :trigger-change="true" dictCode="" placeholder="请选择技术职称"/>
        </a-form-item>
        <a-form-item label="从事专业" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['professorWorkMajor']" placeholder="请输入从事专业"></a-input>
        </a-form-item>
        <a-form-item label="从事专业时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择从事专业时间" v-decorator="['professorMajorDate']" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="身份证号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['professorIdentity']" placeholder="请输入身份证号"></a-input>
        </a-form-item>
        <a-form-item label="家庭地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['professorHomeAddress']" placeholder="请输入家庭地址"></a-input>
        </a-form-item>
        <a-form-item label="健康状况" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['professorHealth']" :trigger-change="true" dictCode="" placeholder="请选择健康状况"/>
        </a-form-item>
        <a-form-item label="办公电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['professorOfficeTel']" placeholder="请输入办公电话"></a-input>
        </a-form-item>
        <a-form-item label="手机" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['professorPhone']" placeholder="请输入手机"></a-input>
        </a-form-item>
        <a-form-item label="本人项目简介" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['professorProjectIntroduce']" rows="4" placeholder="请输入本人项目简介"/>
        </a-form-item>
        <a-form-item label="业务主管 部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['professorLeadMsg']" rows="4" placeholder="请输入业务主管 部门"/>
        </a-form-item>
        <a-form-item label="行政审批局意见" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['professorApproveMsg']" rows="4" placeholder="请输入行政审批局意见"/>
        </a-form-item>
        <a-form-item label="照片" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-image-upload isMultiple v-decorator="['professorPhoto']"></j-image-upload>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'  
  import JImageUpload from '@/components/jeecg/JImageUpload'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"
  
  export default {
    name: "DiyProfessorInfoModal",
    components: { 
      JDate,
      JImageUpload,
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/org/diyProfessorInfo/add",
          edit: "/org/diyProfessorInfo/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'professorType','professorName','professorSex','professorBirthday','professorSchool','professorMajor','professorGraduateDate','professorEducationBackground','professorDegree','professorWorkUnit','professorAddress','professorDeclareCategory','professorPosition','professorBeginWork','professorTitle','professorWorkMajor','professorMajorDate','professorIdentity','professorHomeAddress','professorHealth','professorOfficeTel','professorPhone','professorProjectIntroduce','professorLeadMsg','professorApproveMsg','professorPhoto'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'professorType','professorName','professorSex','professorBirthday','professorSchool','professorMajor','professorGraduateDate','professorEducationBackground','professorDegree','professorWorkUnit','professorAddress','professorDeclareCategory','professorPosition','professorBeginWork','professorTitle','professorWorkMajor','professorMajorDate','professorIdentity','professorHomeAddress','professorHealth','professorOfficeTel','professorPhone','professorProjectIntroduce','professorLeadMsg','professorApproveMsg','professorPhoto'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>